package com.iscale.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.iscale.model.dto.Pager;
import com.iscale.model.entity.BaseBrandInfo;
import com.iscale.mapper.BaseBrandInfoMapper;
import com.iscale.model.entity.SysUser;
import com.iscale.service.BaseBrandInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.iscale.util.StringUtil;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 品牌管理 服务实现类
 * </p>
 *
 * @author Andychen
 * @since 2017-03-10
 */
@Service
public class BaseBrandInfoServiceImpl extends ServiceImpl<BaseBrandInfoMapper, BaseBrandInfo> implements BaseBrandInfoService {

    @Override
    public  Pager<BaseBrandInfo> selectBrandsByPager(int page, int size,String merchantNo){
        RowBounds bounds = new RowBounds((page-1)*size,size);
        EntityWrapper<BaseBrandInfo> entityWrapper = new EntityWrapper<>(new BaseBrandInfo());
        entityWrapper.where("status={0}",0).andNew("ptype={0}",0);
        if(StringUtil.isNotEmpty(merchantNo)){
            entityWrapper.or("merchantNo={0}",merchantNo);
        }
        entityWrapper.orderBy("createTime",true);
        List<BaseBrandInfo> ls =  baseMapper.selectPage(bounds,entityWrapper);
        Integer count = baseMapper.selectCount(entityWrapper);
        return new Pager<>(count,ls);
    }
}
